package com.zb.network.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjNetworkEmpSkillService;
import com.zb.service.impl.ZjNetworkEmpSkillServiceImpl;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkEmpSkillVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 网点人员技能表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-01-29
 */
@Api(tags = "服务商人员技能类接口")
@RestController
@RequestMapping("/network/emp/skill")
public class ZjNetworkEmpSkillController {
    @Resource
    private ZjNetworkEmpSkillService networkEmpSkillService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "服务区域-服务商设置-工程师技能 - 新增或更新服务商人员技能")
    @ApiOperation("新增或更新服务商人员技能")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid NetworkEmpSkillVo empSkillVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkEmpSkillService.save(custAccId, empSkillVo);
        return Result.success(null != empSkillVo.getId()? "更新服务商人员技能成功" : "新增服务商人员技能成功");
    }

    @ApiOperation("获取人员技能列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取人员技能列表成功").data(networkEmpSkillService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据技能ID获取技能详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "技能ID", required = true) Long id) {
        return Result.success("获取技能详情成功").data(PageUtil.row(networkEmpSkillService.getDetail(id)));
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商设置-工程师技能 - 批量启用或禁用技能")
    @ApiOperation("批量启用或禁用技能")
    @PostMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "技能状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "技能ID", required = true) List<Long> ids) {
        networkEmpSkillService.updateDisabledBatchById(ids, status);
        return Result.success(status? "禁用技能成功" : "启用技能成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.DELETE, remark = "服务区域-服务商设置-工程师技能 - 删除技能")
    @ApiOperation("删除技能")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody List<Long> ids) {
        networkEmpSkillService.deleteBatchById(ids);
        return Result.success("删除技能成功");
    }



}
